package strategy.improve;

import strategy.improve.behavior.fly.FlyBehavior;
import strategy.improve.behavior.fly.NoFlyBehavior;
import strategy.improve.behavior.run.NoRunBehavior;
import strategy.improve.behavior.run.RunBehavior;
import strategy.improve.behavior.swim.NoSwimBehavior;
import strategy.improve.behavior.swim.SwimBehavior;

public abstract class Duck {
    // 添加所有行为族，默认空行为
    protected RunBehavior runBehavior = new NoRunBehavior();
    protected SwimBehavior swimBehavior = new NoSwimBehavior();
    protected FlyBehavior flyBehavior = new NoFlyBehavior();

    public abstract void display();

    public void run() {
        this.runBehavior.run();
    }

    public void swim() {
        this.swimBehavior.swim();
    }

    public void fly() {
        this.flyBehavior.fly();
    }

    // 优化：动态改变行为
    public void setRunBehavior(RunBehavior newRunBehavior) {
        this.runBehavior = newRunBehavior;
    }

    public void setSwimBehavior(SwimBehavior newSwimBehavior) {
        this.swimBehavior = newSwimBehavior;
    }

    public void setFlyBehavior(FlyBehavior newFlyBehavior) {
        this.flyBehavior = newFlyBehavior;
    }
}
